package hpu.bitenergy.util;

import java.net.UnknownHostException;

import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBConnector;
import com.mongodb.Mongo;
import com.mongodb.MongoException;

public class MongoDBHerlper {
	private static final String HOST="127.0.0.1";
	private static final int PORT=27017;
	
	private Mongo mo=null;
	
	public MongoDBHerlper(){
			try {
				mo=new Mongo(HOST, PORT);
				
			} catch (UnknownHostException | MongoException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	
	}
	

	public void cratemongo() throws UnknownHostException, MongoException {
		mo = new Mongo();
	}

	public DBCollection GetDB(String dbname, String collname) {

		DB db = mo.getDB(dbname);
		DBCollection col = db.getCollection(collname);

		return col;

	}
	public void close(){
		this.mo.close();
	}
}
